package com.uzai.console.web.mini;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.uzai.console.annotation.SystemLogType;
import com.uzai.console.dto.BaseDto;
import com.uzai.console.dto.mini.miniorder.MiniOrderIdDto;
import com.uzai.console.dto.mini.miniorder.MiniOrderQuery;
import com.uzai.console.dto.mini.miniorder.MiniOrderSendDto;
import com.uzai.console.enums.OperationTypeEnum;
import com.uzai.console.enums.SystemModelEnum;
import com.uzai.console.service.mini.MiniOrderService;
import com.uzai.console.vo.mini.miniorder.MiniOrderVo;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 小程序团购订单管理
 * @author liuqi
 * @date 2021年08月16日 15:11
 */
@Api(value = "团购订单",tags = "微信小程序|团购订单")
@ApiSort(7)
@RestController
public class MiniOrderController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(MiniOrderController.class);

    @Autowired
    private MiniOrderService miniOrderService;

    @ApiOperation(value = "分页查询小程序团购订单列表", notes = "分页查询小程序团购订单列表", response = MiniOrderVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/miniOrder/findByPage")
    public Object fingMiniOrderByPage(@RequestBody MiniOrderQuery miniOrderQuery){
        if(miniOrderQuery.getRefundStatus() == null){
            miniOrderQuery.setRefundStatus(0); //默认查询正常的订单
        }
        return miniOrderService.findMiniOrderByPage(miniOrderQuery);
    }

    @ApiOperation(value = "查询小程序团购订单详情", notes = "查询小程序团购订单详情", response = MiniOrderVo.class)
    @ApiOperationSupport(order = 2)
    @PostMapping("/miniOrder/findById")
    public Object findCmsMerTbOrderList(@RequestBody MiniOrderIdDto miniOrderIdDto){
        return miniOrderService.findMiniOrderById(miniOrderIdDto);
    }

    @SystemLogType(model = SystemModelEnum.MiniOrder, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "删除小程序团购订单信息", notes = "删除小程序团购订单信息")
    @ApiOperationSupport(order = 3)
    @PostMapping("/miniOrder/delete")
    public Object deleteMiniOrder(@RequestBody MiniOrderIdDto miniOrderIdDto){
        miniOrderService.deleteMiniOrder(miniOrderIdDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.MiniOrder, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "小程序团购订单发货", notes = "小程序团购订单发货")
    @ApiOperationSupport(order = 4)
    @PostMapping("/miniOrder/send")
    public Object sendMiniOrder(@RequestBody MiniOrderSendDto miniOrderSendDto){
        miniOrderService.sendMiniOrder(miniOrderSendDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.MiniOrder, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "小程序团购订单确认收货", notes = "小程序团购订单确认收货")
    @ApiOperationSupport(order = 5)
    @PostMapping("/miniOrder/confirmReceive")
    public Object confirmReceiveMiniOrder(@RequestBody MiniOrderIdDto miniOrderIdDto){
        miniOrderService.confirmReceiveMiniOrder(miniOrderIdDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.MiniOrder, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "小程序团购订单取消", notes = "小程序团购订单取消")
    @ApiOperationSupport(order = 5)
    @PostMapping("/miniOrder/cancel")
    public Object cancelMiniOrder(@RequestBody MiniOrderIdDto miniOrderIdDto){
        miniOrderService.cancelMiniOrder(miniOrderIdDto);
        return true;
    }

}
